<?php
namespace app\smallapp\controller;
use app\common\controller\BaseApi;

/**
 * pt 跟进工具类
 * */
class PTFollow extends BaseApi{
	function _initialize() {
		
	}
	 /**
	  * 用户购买私教课程前添加默认跟进
	  * @param $pt_order_id pt 订单id
	  * */
	 function after_pt_deal($pt_order_id){
	 	$PtOrder=db("GymPtOrder")->find($pt_order_id);
		if(!empty($PtOrder)){
			$follow_id=db("GymPtFollow")->insertGetId(array(
			"pt_id"=>$PtOrder['pt_id'],
			"member_id"=>$PtOrder['member_id'],
			"shop_id"=>$PtOrder['shop_id'],
			"type"=>1,
			"remarks"=>"购入pt订单时候的自动生成",
			"follow_time"=>date("Y-m-d H:i:s"),
			"status"=>1,
			"pt_order_id"=>$PtOrder["id"],
			));
			$this->after_pt_follow($PtOrder["id"],$follow_id);	
		}else{
			$this->api_ajax_error("","pt_order_id 错误");
		}
	 }
	 /**
	  * pt 跟进后的统计操作
	  * @param $follow_id pt跟进id
	  * @param $pt_order_id 私教课程id
	  * */
	function after_pt_follow($pt_order_id,$follow_id){
		$PtOrder=db("GymPtOrder")->find($pt_order_id);
		$follow=db("GymPtFollow")->find($follow_id);
		if(!empty($PtOrder)&&!empty($follow)){
			db("GymPtOrder")->where("id=$pt_order_id")->setField([
					"follow_count"=>$PtOrder['follow_count']+1,
					"last_follow_time"=>$follow['follow_time'],
					"last_follow_id"=>$follow_id,
			]);
		}else{
			$this->api_ajax_error("","pt_order_id 或者 follow_id 错误");
		}			 	
	}
	 
	/**
	  * pt 预约后的统计操作
	  * @param $follow_id pt跟进id
	  * @param $pt_order_id 私教课程id
	  * */
	 function after_pt_order($pt_order_id,$follow_id){
		$PtOrder=db("GymPtOrder")->find($pt_order_id);
		$follow=db("GymPtFollow")->find($follow_id);
		if(!empty($PtOrder)){
			db("GymPtOrder")->where("id=$pt_order_id")->setField([
					"order_count"=>$PtOrder['order_count']+1,
					"last_order_time"=>$follow['order_date']." ".$follow['order_time'],
					"last_order_id"=>$follow_id,
			]);
		}else{
			$this->api_ajax_error("","pt_order_id 或者 follow_id 错误");
		}			 	
	 }
	/**
	  * pt 上课后的统计操作
	  * @param $follow_id pt跟进id
	  * @param $pt_order_id 私教课程id
	  * */
	 function after_start_course($pt_order_id,$follow_id){
	 	
	 } 
	 
	 //////////////////////////////////////
	 ///smartgym.com/smallapp/PTFollow/test
	 function test(){
//	 	$this->after_pt_deal(2);
//		$this->after_pt_follow(1, 1);
		$this->after_pt_order(4, 4);
		var_dump("chengg");die;
	 }
}
